<?php
require_once "../libraries/utilities/functions.php";
$path = "../../ptnhuan-web1/data/films.txt";
$full_path = realpath($path);
$films = mreadFile($full_path);
?>
<form method="POST">
    <?php
    for ($i = 0; $i < count($films); $i++) {
        $a = trim($films[$i], "\t\n\r");
        $film = explode(";", $a);
        if ($_GET["if"] == $film[0]) {
            ?>
            <img src="../../ptnhuan-web1/public/images/films/<?php echo $film[1]; ?>"width="50px"><br>
            Film name:&nbsp;<input  type="text" name="title" width="60px" value="<?php if (isset($film[2])) echo $film[2]; ?>">
            Rating:&nbsp; <input type="text" name="rating" value="<?php if (isset($film[3])) echo $film[3]; ?>">
            <br>
            <textarea placeholder="disdrection" rows="4" cols="50"></textarea>
            <br>
            <input type="submit" name="submit" value="save">
        <?php }
    }
    ?>   
</form>
<a href="file4.php?uid=.$users[$index]['id'])">Goback</a>


<?php
if (isset($_POST["submit"])) {
    for ($i = 0; $i < count($films); $i++) {
        $b = trim($films[$i], " \t\n\r");
        if (!empty($b)) {
            $films[$i] = explode(";", $b);
            if ($_GET["if"] == $films[$i][0]) {
                $films[$i][2] = $_POST["title"];
                $films[$i][3] = $_POST["rating"];
            }
        } else {
            $films[$i] = $b;
        }
    }
    mwriteFile($films);
}
?>

